#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,q,t1,t2,t3,t4,v[2005][2005],dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},ans,cnt;
char a[2005][2005];
struct ok{
    int x,y,X,Y,id;
    bool operator < (const ok &A) const{
        if(x==A.x){
            if(X==A.X){
                if(y==A.y) return Y<A.y;
                return y<A.y;
            }
            return X<A.X;
        }
        return x<A.x;
    }
}b[2000005];
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
inline void dfs(int x,int y,int g){
    v[x][y]=g;
    for(int i=0;i<4;i++){
        int tx=x+dx[i],ty=y+dy[i];
        if(tx<t1||tx>t3||ty<t2||ty>t4||v[tx][ty]==g||a[tx][ty]=='0') continue;
        dfs(tx,ty,g);
    }
}
signed main(){
    freopen("unicom.in","r",stdin);
    freopen("unicom.out","w",stdout);
    n=read(),m=read(),q=read();
    for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
        for(int i=1;i<=q;i++){
            t1=read(),t2=read(),t3=read(),t4=read();
            ans=0;
            for(int j=t1;j<=t3;j++){
                for(int g=t2;g<=t4;g++){
                    if(a[j][g]=='1'&&v[j][g]!=i) dfs(j,g,i),ans++; 
                }
            }
            cout<<ans<<"\n";
        }
    
    return 0;
}